package com.neusoft.yuejian26.yuejian_26.Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.neusoft.yuejian26.yuejian_26.Adapter.MyShareAdapter;
import com.neusoft.yuejian26.yuejian_26.Bean.MySharebean;
import com.neusoft.yuejian26.yuejian_26.Other.CacheInfo;
import com.neusoft.yuejian26.yuejian_26.R;
import com.neusoft.yuejian26.yuejian_26.model.PostModel;
import com.neusoft.yuejian26.yuejian_26.network.RetrofitCallback;

import java.util.List;

import retrofit2.Call;

public class MyShareActivity extends AppCompatActivity {

    public ImageView svg_back;
    public View view = null;
    XRecyclerView myshare_list;
    private String uid=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_share);
        initview();
        initEvent();
        getMyShareList();
    }

    private void getMyShareList(){
        uid=new CacheInfo(MyShareActivity.this).getUserIdCache();
        PostModel postModel = new PostModel();
        Call call = postModel.myShareList(uid,"1");
        postModel.bindCallback(call, new RetrofitCallback() {
            @Override
            public void onResponse(Object o) {
                List<MySharebean> mslist = (List<MySharebean>) o;
                myshare_list.setAdapter(new MyShareAdapter(MyShareActivity.this,mslist));
            }
        });
    }

    private void initview(){
        myshare_list= (XRecyclerView) findViewById(R.id.myshare_list);
        svg_back= (ImageView) findViewById(R.id.svg_back);
    }

    private void initEvent(){
        myshare_list.setLayoutManager(new LinearLayoutManager(MyShareActivity.this));
        svg_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MyShareActivity.this,MainActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("page",4);
                intent.putExtras(bundle);
                startActivity(intent);
                finish();
            }
        });
    }

}
